/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     2025/6/24 15:20:35                           */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('bs_product') and o.name = 'FK_BS_PRODU_拥有_BS_PRODU')
alter table bs_product
   drop constraint FK_BS_PRODU_拥有_BS_PRODU
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('"bs_product_img (货品信息图片表)"') and o.name = 'FK_BS_PRODU_拥有_BS_PRODU')
alter table "bs_product_img (货品信息图片表)"
   drop constraint FK_BS_PRODU_拥有_BS_PRODU
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('bs_product_unit') and o.name = 'FK_BS_PRODU_拥有_BS_PRODU')
alter table bs_product_unit
   drop constraint FK_BS_PRODU_拥有_BS_PRODU
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('bs_slot') and o.name = 'FK_BS_SLOT_拥有_BS_WAREH')
alter table bs_slot
   drop constraint FK_BS_SLOT_拥有_BS_WAREH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('bs_stock') and o.name = 'FK_BS_STOCK_拥有_BS_PRODU')
alter table bs_stock
   drop constraint FK_BS_STOCK_拥有_BS_PRODU
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('bs_stock') and o.name = 'FK_BS_STOCK_拥有_BS_SLOT')
alter table bs_stock
   drop constraint FK_BS_STOCK_拥有_BS_SLOT
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('bs_stock') and o.name = 'FK_BS_STOCK_拥有_BS_WAREH')
alter table bs_stock
   drop constraint FK_BS_STOCK_拥有_BS_WAREH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ic_check_d') and o.name = 'FK_IC_CHECK_对应_BS_SLOT')
alter table ic_check_d
   drop constraint FK_IC_CHECK_对应_BS_SLOT
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ic_check_d') and o.name = 'FK_IC_CHECK_拥有_IC_CHECK')
alter table ic_check_d
   drop constraint FK_IC_CHECK_拥有_IC_CHECK
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('"ic_check_h （盘点表（主表））"') and o.name = 'FK_IC_CHECK_对应_BS_WAREH')
alter table "ic_check_h （盘点表（主表））"
   drop constraint FK_IC_CHECK_对应_BS_WAREH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('in_instock_d') and o.name = 'FK_IN_INSTO_对应_BS_SLOT')
alter table in_instock_d
   drop constraint FK_IN_INSTO_对应_BS_SLOT
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('in_instock_d') and o.name = 'FK_IN_INSTO_拥有_IN_INSTO')
alter table in_instock_d
   drop constraint FK_IN_INSTO_拥有_IN_INSTO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('in_instock_h') and o.name = 'FK_IN_INSTO_对应_BS_WAREH')
alter table in_instock_h
   drop constraint FK_IN_INSTO_对应_BS_WAREH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_purchase_d') and o.name = 'FK_ORD_PURC_对应_BS_PRODU')
alter table ord_purchase_d
   drop constraint FK_ORD_PURC_对应_BS_PRODU
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_purchase_d') and o.name = 'FK_ORD_PURC_拥有_ORD_PURC')
alter table ord_purchase_d
   drop constraint FK_ORD_PURC_拥有_ORD_PURC
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_purchase_h') and o.name = 'FK_ORD_PURC_拥有_BS_SUPPL')
alter table ord_purchase_h
   drop constraint FK_ORD_PURC_拥有_BS_SUPPL
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_purchase_return_d') and o.name = 'FK_ORD_PURC_对应_ORD_PURC')
alter table ord_purchase_return_d
   drop constraint FK_ORD_PURC_对应_ORD_PURC
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_purchase_return_d') and o.name = 'FK_ORD_PURC_拥有_ORD_PURC')
alter table ord_purchase_return_d
   drop constraint FK_ORD_PURC_拥有_ORD_PURC
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_purchase_return_h') and o.name = 'FK_ORD_PURC_对应_ORD_PURC')
alter table ord_purchase_return_h
   drop constraint FK_ORD_PURC_对应_ORD_PURC
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_sale_d') and o.name = 'FK_ORD_SALE_对应_BS_STOCK')
alter table ord_sale_d
   drop constraint FK_ORD_SALE_对应_BS_STOCK
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_sale_d') and o.name = 'FK_ORD_SALE_拥有_ORD_SALE')
alter table ord_sale_d
   drop constraint FK_ORD_SALE_拥有_ORD_SALE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('"ord_sale_h (销售订单表（主表）)"') and o.name = 'FK_ORD_SALE_拥有_BS_CUSTO')
alter table "ord_sale_h (销售订单表（主表）)"
   drop constraint FK_ORD_SALE_拥有_BS_CUSTO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_sale_return_d') and o.name = 'FK_ORD_SALE_对应_ORD_SALE')
alter table ord_sale_return_d
   drop constraint FK_ORD_SALE_对应_ORD_SALE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_sale_return_d') and o.name = 'FK_ORD_SALE_拥有_ORD_SALE')
alter table ord_sale_return_d
   drop constraint FK_ORD_SALE_拥有_ORD_SALE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ord_sale_return_h') and o.name = 'FK_ORD_SALE_对应_ORD_SALE')
alter table ord_sale_return_h
   drop constraint FK_ORD_SALE_对应_ORD_SALE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('out_outstock_d') and o.name = 'FK_OUT_OUTS_对应_BS_SLOT')
alter table out_outstock_d
   drop constraint FK_OUT_OUTS_对应_BS_SLOT
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('out_outstock_d') and o.name = 'FK_OUT_OUTS_拥有_OUT_OUTS')
alter table out_outstock_d
   drop constraint FK_OUT_OUTS_拥有_OUT_OUTS
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('out_outstock_h') and o.name = 'FK_OUT_OUTS_对应_BS_WAREH')
alter table out_outstock_h
   drop constraint FK_OUT_OUTS_对应_BS_WAREH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('sys_dict_data') and o.name = 'FK_SYS_DICT_拥有_SYS_DICT')
alter table sys_dict_data
   drop constraint FK_SYS_DICT_拥有_SYS_DICT
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('tr_allot_d') and o.name = 'FK_TR_ALLOT_拥有_TR_ALLOT')
alter table tr_allot_d
   drop constraint FK_TR_ALLOT_拥有_TR_ALLOT
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('zct_user') and o.name = 'FK_ZCT_USER_拥有_ZCT_DEPA')
alter table zct_user
   drop constraint FK_ZCT_USER_拥有_ZCT_DEPA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('zct_user') and o.name = 'FK_ZCT_USER_拥有_ZCT_POSI')
alter table zct_user
   drop constraint FK_ZCT_USER_拥有_ZCT_POSI
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('对应') and o.name = 'FK_对应_对应_ZCT_ROLE')
alter table 对应
   drop constraint FK_对应_对应_ZCT_ROLE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('对应') and o.name = 'FK_对应_对应_ZCT_USER')
alter table 对应
   drop constraint FK_对应_对应_ZCT_USER
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('对应2') and o.name = 'FK_对应2_对应_ZCT_PERM')
alter table 对应2
   drop constraint FK_对应2_对应_ZCT_PERM
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('对应2') and o.name = 'FK_对应2_对应_ZCT_ROLE')
alter table 对应2
   drop constraint FK_对应2_对应_ZCT_ROLE
go

if exists (select 1
            from  sysobjects
           where  id = object_id('bs_customer')
            and   type = 'U')
   drop table bs_customer
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('bs_product')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index bs_product.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('bs_product')
            and   type = 'U')
   drop table bs_product
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('"bs_product_img (货品信息图片表)"')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index "bs_product_img (货品信息图片表)".拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('"bs_product_img (货品信息图片表)"')
            and   type = 'U')
   drop table "bs_product_img (货品信息图片表)"
go

if exists (select 1
            from  sysobjects
           where  id = object_id('bs_product_type')
            and   type = 'U')
   drop table bs_product_type
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('bs_product_unit')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index bs_product_unit.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('bs_product_unit')
            and   type = 'U')
   drop table bs_product_unit
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('bs_slot')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index bs_slot.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('bs_slot')
            and   type = 'U')
   drop table bs_slot
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('bs_stock')
            and   name  = '拥有_FK3'
            and   indid > 0
            and   indid < 255)
   drop index bs_stock.拥有_FK3
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('bs_stock')
            and   name  = '拥有_FK2'
            and   indid > 0
            and   indid < 255)
   drop index bs_stock.拥有_FK2
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('bs_stock')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index bs_stock.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('bs_stock')
            and   type = 'U')
   drop table bs_stock
go

if exists (select 1
            from  sysobjects
           where  id = object_id('bs_supplier')
            and   type = 'U')
   drop table bs_supplier
go

if exists (select 1
            from  sysobjects
           where  id = object_id('bs_warehouse')
            and   type = 'U')
   drop table bs_warehouse
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ic_check_d')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index ic_check_d.对应_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ic_check_d')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index ic_check_d.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ic_check_d')
            and   type = 'U')
   drop table ic_check_d
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('"ic_check_h （盘点表（主表））"')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index "ic_check_h （盘点表（主表））".对应_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('"ic_check_h （盘点表（主表））"')
            and   type = 'U')
   drop table "ic_check_h （盘点表（主表））"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('in_instock_d')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index in_instock_d.对应_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('in_instock_d')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index in_instock_d.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('in_instock_d')
            and   type = 'U')
   drop table in_instock_d
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('in_instock_h')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index in_instock_h.对应_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('in_instock_h')
            and   type = 'U')
   drop table in_instock_h
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_purchase_d')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_purchase_d.对应_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_purchase_d')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_purchase_d.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ord_purchase_d')
            and   type = 'U')
   drop table ord_purchase_d
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_purchase_h')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_purchase_h.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ord_purchase_h')
            and   type = 'U')
   drop table ord_purchase_h
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_purchase_return_d')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_purchase_return_d.对应_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_purchase_return_d')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_purchase_return_d.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ord_purchase_return_d')
            and   type = 'U')
   drop table ord_purchase_return_d
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_purchase_return_h')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_purchase_return_h.对应_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ord_purchase_return_h')
            and   type = 'U')
   drop table ord_purchase_return_h
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_sale_d')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_sale_d.对应_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_sale_d')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_sale_d.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ord_sale_d')
            and   type = 'U')
   drop table ord_sale_d
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('"ord_sale_h (销售订单表（主表）)"')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index "ord_sale_h (销售订单表（主表）)".拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('"ord_sale_h (销售订单表（主表）)"')
            and   type = 'U')
   drop table "ord_sale_h (销售订单表（主表）)"
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_sale_return_d')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_sale_return_d.对应_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_sale_return_d')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_sale_return_d.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ord_sale_return_d')
            and   type = 'U')
   drop table ord_sale_return_d
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ord_sale_return_h')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index ord_sale_return_h.对应_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ord_sale_return_h')
            and   type = 'U')
   drop table ord_sale_return_h
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('out_outstock_d')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index out_outstock_d.拥有_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('out_outstock_d')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index out_outstock_d.对应_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('out_outstock_d')
            and   type = 'U')
   drop table out_outstock_d
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('out_outstock_h')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index out_outstock_h.对应_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('out_outstock_h')
            and   type = 'U')
   drop table out_outstock_h
go

if exists (select 1
            from  sysobjects
           where  id = object_id('public_file')
            and   type = 'U')
   drop table public_file
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_business_type')
            and   type = 'U')
   drop table sys_business_type
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_code_rule')
            and   type = 'U')
   drop table sys_code_rule
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_dict_data')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_dict_data.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_dict_data')
            and   type = 'U')
   drop table sys_dict_data
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_dict_type')
            and   type = 'U')
   drop table sys_dict_type
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_info')
            and   type = 'U')
   drop table sys_info
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('tr_allot_d')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index tr_allot_d.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('tr_allot_d')
            and   type = 'U')
   drop table tr_allot_d
go

if exists (select 1
            from  sysobjects
           where  id = object_id('tr_allot_h')
            and   type = 'U')
   drop table tr_allot_h
go

if exists (select 1
            from  sysobjects
           where  id = object_id('zct_department')
            and   type = 'U')
   drop table zct_department
go

if exists (select 1
            from  sysobjects
           where  id = object_id('zct_permission')
            and   type = 'U')
   drop table zct_permission
go

if exists (select 1
            from  sysobjects
           where  id = object_id('zct_position')
            and   type = 'U')
   drop table zct_position
go

if exists (select 1
            from  sysobjects
           where  id = object_id('zct_role')
            and   type = 'U')
   drop table zct_role
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('zct_user')
            and   name  = '拥有_FK2'
            and   indid > 0
            and   indid < 255)
   drop index zct_user.拥有_FK2
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('zct_user')
            and   name  = '拥有_FK'
            and   indid > 0
            and   indid < 255)
   drop index zct_user.拥有_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('zct_user')
            and   type = 'U')
   drop table zct_user
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('对应')
            and   name  = '对应_FK2'
            and   indid > 0
            and   indid < 255)
   drop index 对应.对应_FK2
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('对应')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index 对应.对应_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('对应')
            and   type = 'U')
   drop table 对应
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('对应2')
            and   name  = '对应_FK2'
            and   indid > 0
            and   indid < 255)
   drop index 对应2.对应_FK2
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('对应2')
            and   name  = '对应_FK'
            and   indid > 0
            and   indid < 255)
   drop index 对应2.对应_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('对应2')
            and   type = 'U')
   drop table 对应2
go

/*==============================================================*/
/* Table: bs_customer                                           */
/*==============================================================*/
create table bs_customer (
   cust_id              int                  not null,
   cust_code            varchar(64)          null,
   cust_name            varchar(64)          null,
   cust_address         varchar(224)         null,
   cust_linkman         varchar(64)          null,
   cust_linkphone       varchar(11)          null,
   cust_email           varchar(64)          null,
   cust_industry        varchar(64)          null,
   cust_source          varchar(64)          null,
   cust_depId           int                  null,
   cust_depName         varchar(64)          null,
   cust_userId          int                  null,
   cust_userName        varchar(64)          null,
   cust_status          int                  null,
   cust_accountName     varchar(64)          null,
   cust_taxpayerNum     varchar(64)          null,
   cust_bankAccount     varchar(64)          null,
   cust_openBank        varchar(64)          null,
   cust_openBankAddress varchar(224)         null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_BS_CUSTOMER primary key nonclustered (cust_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bs_customer') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'bs_customer' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '客户信息', 
   'user', @CurrentUser, 'table', 'bs_customer'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户Id',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户编号',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户名称',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_address')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_address'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户地址',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_address'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_linkman')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_linkman'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系人',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_linkman'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_linkphone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_linkphone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系电话',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_linkphone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_email')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_email'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '电子邮件',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_email'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_industry')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_industry'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '所属行业',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_industry'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_source')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_source'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户来源',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_source'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_depId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_depId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售部门Id',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_depId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_depName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_depName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售部门',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_depName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_userId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_userId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售负责人Id',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_userId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_userName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_userName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售负责人',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_userName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_accountName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_accountName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '账户名称',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_accountName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_taxpayerNum')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_taxpayerNum'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '纳税人识别号',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_taxpayerNum'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_bankAccount')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_bankAccount'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '银行账户',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_bankAccount'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_openBank')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_openBank'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '开户银行',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_openBank'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_openBankAddress')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_openBankAddress'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '开户行地址',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'cust_openBankAddress'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_customer')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'bs_customer', 'column', 'remark'
go

/*==============================================================*/
/* Table: bs_product                                            */
/*==============================================================*/
create table bs_product (
   proc_id              int                  not null,
   proc_code            varchar(64)          null,
   proc_name            varchar(64)          null,
   type_id              int                  null,
   type_name            varchar(64)          null,
   proc_model           varchar(64)          null,
   instock_price        decimal(18,2)        null,
   outstock_price       decimal(18,2)        null,
   proc_sort            int                  null,
   proc_status          int                  null,
   proc_expirationdate  varchar(64)          null,
   proc_Warningdays     int                  null,
   proc_inventory       int                  null,
   proc_inventory_money decimal(18,2)        null,
   proc_primary_unit    varchar(64)          null,
   proc_primary_barcode  varchar(64)          null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_BS_PRODUCT primary key nonclustered (proc_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bs_product') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'bs_product' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '货品详细信息', 
   'user', @CurrentUser, 'table', 'bs_product'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品信息ID',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'type_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'type_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品类型ID',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'type_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品信息编号',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品信息名称',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_model')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_model'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '规格型号',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_model'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'instock_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'instock_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库参考价',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'instock_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outstock_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'outstock_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库参考价',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'outstock_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_expirationdate')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_expirationdate'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '保质期',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_expirationdate'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_Warningdays')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_Warningdays'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '预警天数',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_Warningdays'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_inventory')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_inventory'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '总库存',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_inventory'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_inventory_money')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_inventory_money'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库总总金额',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_inventory_money'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_primary_unit')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_primary_unit'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '主单位',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'proc_primary_unit'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'bs_product', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on bs_product (
type_id ASC
)
go

/*==============================================================*/
/* Table: "bs_product_img (货品信息图片表)"                            */
/*==============================================================*/
create table bs_product_img (
   img_id               int                  not null,
   proc_id              int                  null,
   proc_img             varchar(64)          null,
   constraint "PK_BS_PRODUCT_IMG" primary key nonclustered (img_id)
)
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"bs_product_img (货品信息图片表)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_img (货品信息图片表)', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品信息ID',
   'user', @CurrentUser, 'table', 'bs_product_img (货品信息图片表)', 'column', 'proc_id'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on "bs_product_img (货品信息图片表)" (
proc_id ASC
)
go

/*==============================================================*/
/* Table: bs_product_type                                       */
/*==============================================================*/
create table bs_product_type (
   type_id              int                  not null,
   type_code            varchar(64)          null,
   type_name            varchar(64)          null,
   type_pid             int                  null,
   type_sort            int                  null,
   type_status          int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_BS_PRODUCT_TYPE primary key nonclustered (type_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bs_product_type') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'bs_product_type' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '货品类型信息', 
   'user', @CurrentUser, 'table', 'bs_product_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'type_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品类型ID',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'type_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品类型编号',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'type_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品类型名称',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'type_pid')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_pid'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '上级',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_pid'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'type_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'type_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'type_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'bs_product_type', 'column', 'remark'
go

/*==============================================================*/
/* Table: bs_product_unit                                       */
/*==============================================================*/
create table bs_product_unit (
   auxiliary_id         int                  not null,
   proc_id              int                  null,
   proc_auxiliary_unit  varchar(64)          null,
   proc_auxiliary_barcode  varchar(64)          null,
   proc_auxiliary_num   int                  null,
   constraint PK_BS_PRODUCT_UNIT primary key nonclustered (auxiliary_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bs_product_unit') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'bs_product_unit' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '辅助单位可以有多个', 
   'user', @CurrentUser, 'table', 'bs_product_unit'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_unit')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'auxiliary_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_unit', 'column', 'auxiliary_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品辅助单位ID',
   'user', @CurrentUser, 'table', 'bs_product_unit', 'column', 'auxiliary_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_unit')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_unit', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品信息ID',
   'user', @CurrentUser, 'table', 'bs_product_unit', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_unit')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_auxiliary_unit')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_unit', 'column', 'proc_auxiliary_unit'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '辅助单位',
   'user', @CurrentUser, 'table', 'bs_product_unit', 'column', 'proc_auxiliary_unit'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_product_unit')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_auxiliary_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_product_unit', 'column', 'proc_auxiliary_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '辅助单位数量',
   'user', @CurrentUser, 'table', 'bs_product_unit', 'column', 'proc_auxiliary_num'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on bs_product_unit (
proc_id ASC
)
go

/*==============================================================*/
/* Table: bs_slot                                               */
/*==============================================================*/
create table bs_slot (
   slot_id              int                  not null,
   wh_id                int                  null,
   slot_code            varchar(64)          null,
   slot_name            varchar(64)          null,
   slot_capacity        int                  null,
   slot_userId          int                  null,
   slot_userName        varchar(64)          null,
   slot_sort            int                  null,
   slot_status          int                  null,
   wh_Name              varchar(64)          null,
   remark               varchar(224)         null,
   constraint PK_BS_SLOT primary key nonclustered (slot_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bs_slot') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'bs_slot' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '仓库库位信息', 
   'user', @CurrentUser, 'table', 'bs_slot'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位ID',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'wh_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库ID',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'wh_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位编号',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位名称',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_capacity')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_capacity'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位容量',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_capacity'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_userId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_userId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位主管Id',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_userId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_userName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_userName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位主管',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_userName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'slot_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_Name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'wh_Name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '所属仓库名称',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'wh_Name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_slot')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'bs_slot', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on bs_slot (
wh_id ASC
)
go

/*==============================================================*/
/* Table: bs_stock                                              */
/*==============================================================*/
create table bs_stock (
   stk_id               int                  null,
   proc_id              int                  null,
   wh_id                int                  null,
   slot_id              int                  null,
   stk_code             varchar(64)          null,
   stk_hand_num         int                  null,
   stk_available_num    int                  null,
   stk_total            decimal(18,2)        null,
   stk_price            decimal(18,2)        null,
   remark               varchar(224)         null
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bs_stock') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'bs_stock' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '货品库存', 
   'user', @CurrentUser, 'table', 'bs_stock'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品信息ID',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'wh_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库ID',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'wh_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'slot_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位ID',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'slot_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'stk_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库存ID',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'stk_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库存编号',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'stk_hand_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_hand_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '实际库存量',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_hand_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'stk_available_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_available_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '可用库存量',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_available_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'stk_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库存总金额',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'stk_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '单价（加权平均法）',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'stk_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_stock')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'bs_stock', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on bs_stock (
proc_id ASC
)
go

/*==============================================================*/
/* Index: 拥有_FK2                                                */
/*==============================================================*/
create index 拥有_FK2 on bs_stock (
wh_id ASC
)
go

/*==============================================================*/
/* Index: 拥有_FK3                                                */
/*==============================================================*/
create index 拥有_FK3 on bs_stock (
slot_id ASC
)
go

/*==============================================================*/
/* Table: bs_supplier                                           */
/*==============================================================*/
create table bs_supplier (
   sup_id               int                  not null,
   sup_code             varchar(64)          null,
   sup_name             varchar(64)          null,
   sup_address          varchar(224)         null,
   sup_linkman          varchar(64)          null,
   sup_linkphone        varchar(11)          null,
   sup_email            varchar(64)          null,
   sup_industry         varchar(64)          null,
   sup_type             varchar(64)          null,
   sup_depId            int                  null,
   sup_depName          varchar(64)          null,
   sup_userId           int                  null,
   sup_userName         varchar(64)          null,
   sup_status           int                  null,
   sup_accountName      varchar(64)          null,
   sup_taxpayerNum      varchar(64)          null,
   sup_bankAccount      varchar(64)          null,
   sup_openBank         varchar(64)          null,
   sup_openBankAddress  varchar(224)         null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_BS_SUPPLIER primary key nonclustered (sup_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bs_supplier') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'bs_supplier' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '供应商信息', 
   'user', @CurrentUser, 'table', 'bs_supplier'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商ID',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商编号',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商名称',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_address')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_address'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商地址',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_address'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_linkman')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_linkman'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系人',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_linkman'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_linkphone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_linkphone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系电话',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_linkphone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_email')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_email'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '电子邮件',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_email'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_industry')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_industry'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '所属行业',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_industry'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_type')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_type'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商分类',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_depId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_depId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货部门Id',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_depId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_depName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_depName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货部门',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_depName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_userId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_userId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货负责人Id',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_userId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_userName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_userName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货负责人',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_userName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_accountName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_accountName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '账户名称',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_accountName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_taxpayerNum')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_taxpayerNum'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '纳税人识别号',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_taxpayerNum'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_bankAccount')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_bankAccount'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '银行账户',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_bankAccount'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_openBank')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_openBank'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '开户银行',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_openBank'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_openBankAddress')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_openBankAddress'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '开户行地址',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'sup_openBankAddress'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_supplier')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'bs_supplier', 'column', 'remark'
go

/*==============================================================*/
/* Table: bs_warehouse                                          */
/*==============================================================*/
create table bs_warehouse (
   wh_id                int                  not null,
   wh_code              varchar(64)          null,
   wh_name              varchar(64)          null,
   wh_capacity          int                  null,
   wh_address           varchar(64)          null,
   wh_sort              int                  null,
   wh_status            int                  null,
   wh_depId             int                  null,
   wh_depName           varchar(64)          null,
   wh_userId            int                  null,
   wh_userName          varchar(64)          null,
   wh_userPhone         varchar(11)          null,
   wh_slot_num          int                  null,
   is_default           int                  null,
   is_lock              int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_BS_WAREHOUSE primary key nonclustered (wh_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bs_warehouse') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'bs_warehouse' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '仓库信息', 
   'user', @CurrentUser, 'table', 'bs_warehouse'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库ID',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库编号',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库名称',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_capacity')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_capacity'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库容量',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_capacity'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_address')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_address'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库地址',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_address'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_depId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_depId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库管部门Id',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_depId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_depName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_depName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库管部门',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_depName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_userId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_userId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库主管Id',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_userId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_userName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_userName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库主管',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_userName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_userPhone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_userPhone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系电话',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_userPhone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_slot_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_slot_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位数量',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'wh_slot_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_default')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'is_default'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '是否默认值',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'is_default'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_lock')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'is_lock'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '是否锁定',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'is_lock'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bs_warehouse')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'bs_warehouse', 'column', 'remark'
go

/*==============================================================*/
/* Table: ic_check_d                                            */
/*==============================================================*/
create table ic_check_d (
   icd_id               int                  not null,
   ic_id                int                  null,
   proc_id              int                  null,
   proc_name            varchar(64)          null,
   slot_id              int                  null,
   slot_name            varchar(64)          null,
   icd_num              int                  null,
   profitandloss_num    int                  null,
   icd_status           int                  null,
   icd_price            decimal(18,2)        null,
   profitandloss_total  decimal(18,2)        null,
   instock_status       int                  null,
   outstock_status      int                  null,
   remark               varchar(224)         null,
   constraint PK_IC_CHECK_D primary key nonclustered (icd_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('ic_check_d') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ic_check_d' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '盘点明细', 
   'user', @CurrentUser, 'table', 'ic_check_d'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'icd_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'icd_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点明细ID',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'icd_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ic_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'ic_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点ID',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'ic_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'slot_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位ID',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'slot_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品ID',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'proc_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品名称',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'proc_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'slot_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点库位名称',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'slot_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'icd_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'icd_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点数量',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'icd_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'profitandloss_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'profitandloss_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盈亏数量',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'profitandloss_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'icd_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'icd_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点状态',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'icd_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'icd_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'icd_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点参考价',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'icd_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'profitandloss_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'profitandloss_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盈亏金额',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'profitandloss_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'instock_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'instock_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库状态',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'instock_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outstock_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'outstock_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库状态',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'outstock_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ic_check_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ic_check_d', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on ic_check_d (
ic_id ASC
)
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on ic_check_d (
slot_id ASC
)
go

/*==============================================================*/
/* Table: "ic_check_h （盘点表（主表））"                                */
/*==============================================================*/
create table ic_check_h(
   ic_id                int                  not null,
   ic_code              varchar(64)          null,
   ic_type              varchar(64)          null,
   start_time           datetime             null,
   end_time             datetime             null,
   wh_id                int                  null,
   wh_name              varchar(64)          null,
   ic_user              varchar(64)          null,
   ic_status            int                  null,
   instock_status       int                  null,
   outstock_status      int                  null,
   bookinventory        int                  null,
   bookamount           decimal(18,2)        null,
   check_num            int                  null,
   checkprofit_num      int                  null,
   checklosses_num      int                  null,
   checkprofit_total    decimal(18,2)        null,
   checklosses_total    decimal(18,2)        null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   approver_name        varchar(64)          null,
   approver_time        datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_IC_CHECK_H  primary key nonclustered (ic_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('"ic_check_h （盘点表（主表））"') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '盘点信息', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ic_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点ID',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'wh_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库ID',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'wh_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ic_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点编号',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ic_type')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_type'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点类型',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'start_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'start_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '开始时间',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'start_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'end_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'end_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '结束时间',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'end_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'wh_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点仓库',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'wh_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ic_user')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_user'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '经办人',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_user'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ic_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点结果',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'ic_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'instock_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'instock_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库状态',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'instock_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outstock_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'outstock_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库状态',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'outstock_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'bookinventory')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'bookinventory'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '账面库存',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'bookinventory'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'bookamount')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'bookamount'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '账面金额',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'bookamount'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'check_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'check_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘点数量',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'check_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'checkprofit_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'checkprofit_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘盈数量',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'checkprofit_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'checklosses_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'checklosses_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘亏数量',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'checklosses_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'checkprofit_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'checkprofit_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘盈金额',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'checkprofit_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'checklosses_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'checklosses_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '盘亏金额',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'checklosses_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'approver_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核人',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'approver_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'approver_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核时间',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'approver_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ic_check_h （盘点表（主表））"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ic_check_h （盘点表（主表））', 'column', 'remark'
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on "ic_check_h （盘点表（主表））" (
wh_id ASC
)
go

/*==============================================================*/
/* Table: in_instock_d                                          */
/*==============================================================*/
create table in_instock_d (
   ind_id               int                  not null,
   in_id                int                  null,
   slot_id              int                  null,
   proc_id              int                  null,
   proc_name            varchar(64)          null,
   slot_name            varchar(64)          null,
   ind_numtotal         int                  null,
   ind_price            decimal(18,2)        null,
   ind_num              int                  null,
   ind_instockOK_num    int                  null,
   ind_instockNO_num    int                  null,
   ind_total            decimal(18,2)        null,
   proc_date            datetime             null,
   remark               varchar(224)         null,
   constraint PK_IN_INSTOCK_D primary key nonclustered (ind_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('in_instock_d') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'in_instock_d' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '入库明细', 
   'user', @CurrentUser, 'table', 'in_instock_d'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ind_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库明细ID',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'in_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库ID',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'in_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'slot_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位ID',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'slot_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品ID',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'proc_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品名称',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'proc_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'slot_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位名称',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'slot_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ind_numtotal')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_numtotal'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库总数量',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_numtotal'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ind_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库单价',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ind_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '本次入库数量',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ind_instockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_instockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已入库数量',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_instockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ind_instockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_instockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未入库数量',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_instockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ind_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库金额',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'ind_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'proc_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '生产日期',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'proc_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'in_instock_d', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on in_instock_d (
in_id ASC
)
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on in_instock_d (
slot_id ASC
)
go

/*==============================================================*/
/* Table: in_instock_h                                          */
/*==============================================================*/
create table in_instock_h (
   in_id                int                  not null,
   in_code              varchar(64)          null,
   in_type              varchar(64)          null,
   wh_id                int                  null,
   wh_name              varchar(64)          null,
   in_date              datetime             null,
   in_order             varchar(64)          null,
   sup_id               int                  null,
   sup_name             varchar(64)          null,
   sup_linkman          varchar(64)          null,
   sup_linkphone        varchar(11)          null,
   in_user              varchar(64)          null,
   in_categories        int                  null,
   in_num               int                  null,
   in_total             decimal(18,2)        null,
   in_instockOK_num     int                  null,
   in_instockNO_num     int                  null,
   in_status            int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   approver_name        varchar(64)          null,
   approver_time        datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_IN_INSTOCK_H primary key nonclustered (in_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('in_instock_h') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'in_instock_h' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '货品进货入库，调拨入库，退货入库', 
   'user', @CurrentUser, 'table', 'in_instock_h'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库ID',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库编号',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_type')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_type'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库类型',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'wh_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库ID',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'wh_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'wh_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库名称',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'wh_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库日期',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_order')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_order'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '关联订单号',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_order'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'sup_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商Id',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'sup_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'sup_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商名称',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'sup_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_linkman')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'sup_linkman'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系人',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'sup_linkman'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_linkphone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'sup_linkphone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系方式',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'sup_linkphone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_user')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_user'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '经办人',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_user'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_categories')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_categories'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库种类',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_categories'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库数量',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库总金额',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_instockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_instockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已入库数量',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_instockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_instockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_instockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未入库数量',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_instockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'in_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'approver_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核人',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'approver_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'approver_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核时间',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'approver_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('in_instock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'in_instock_h', 'column', 'remark'
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on in_instock_h (
wh_id ASC
)
go

/*==============================================================*/
/* Table: ord_purchase_d                                        */
/*==============================================================*/
create table ord_purchase_d (
   purd_id              int                  not null,
   pur_id               int                  null,
   proc_id              int                  null,
   proc_name            varchar(64)          null,
   proc_pur_num         int                  null,
   proc_pur_price       decimal(18,2)        null,
   proc_pur_total       decimal(18,2)        null,
   purd_instockOK_num   int                  null,
   purd_instockNo_num   int                  null,
   purd_returned_num    int                  null,
   remark               varchar(224)         null,
   constraint PK_ORD_PURCHASE_D primary key nonclustered (purd_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('ord_purchase_d') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ord_purchase_d' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '进货订单详细信息', 
   'user', @CurrentUser, 'table', 'ord_purchase_d'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purd_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'purd_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货明细ID',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'purd_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'pur_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货订单ID',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'pur_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品信息ID',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_pur_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'proc_pur_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货货品数量',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'proc_pur_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_pur_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'proc_pur_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货单价',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'proc_pur_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_pur_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'proc_pur_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货货品总金额',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'proc_pur_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purd_instockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'purd_instockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已入库数量',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'purd_instockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purd_instockNo_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'purd_instockNo_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未入库数量',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'purd_instockNo_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purd_returned_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'purd_returned_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已退货数量',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'purd_returned_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ord_purchase_d', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on ord_purchase_d (
pur_id ASC
)
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on ord_purchase_d (
proc_id ASC
)
go

/*==============================================================*/
/* Table: ord_purchase_h                                        */
/*==============================================================*/
create table ord_purchase_h (
   pur_id               int                  not null,
   sup_id               int                  null,
   pur_code             varchar(64)          null,
   pur_date             datetime             null,
   sup_name             varchar(64)          null,
   sup_linkman          varchar(64)          null,
   sup_linkphone        varchar(11)          null,
   pur_depId            char(10)             null,
   pur_depName          varchar(64)          null,
   pur_userId           char(10)             null,
   pur_userName         varchar(64)          null,
   pur_categories       int                  null,
   pur_num              int                  null,
   pur_total            decimal(18,2)        null,
   pur_instockOK_num    int                  null,
   pur_instockNO_num    int                  null,
   purd_returned_num    char(10)             null,
   pur_status           int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   approver_name        varchar(64)          null,
   approver_time        datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_ORD_PURCHASE_H primary key nonclustered (pur_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('ord_purchase_h') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ord_purchase_h' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '进货订单信息', 
   'user', @CurrentUser, 'table', 'ord_purchase_h'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货订单ID',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'sup_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商ID',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'sup_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货订单编号',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货日期',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'sup_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商名称',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'sup_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_linkman')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'sup_linkman'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系人',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'sup_linkman'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_linkphone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'sup_linkphone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系电话',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'sup_linkphone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_depId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_depId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货部门ID',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_depId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_depName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_depName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货部门',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_depName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_userId')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_userId'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货人ID',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_userId'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_userName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_userName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货人',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_userName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_categories')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_categories'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货种类',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_categories'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货数量',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货总金额',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_instockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_instockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已入库数量',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_instockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_instockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_instockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未入库数量',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_instockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purd_returned_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'purd_returned_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已退货数量',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'purd_returned_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'pur_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'approver_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核人',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'approver_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'approver_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核时间',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'approver_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ord_purchase_h', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on ord_purchase_h (
sup_id ASC
)
go

/*==============================================================*/
/* Table: ord_purchase_return_d                                 */
/*==============================================================*/
create table ord_purchase_return_d (
   purtd_id             int                  not null,
   purt_id              int                  null,
   purd_id              int                  null,
   proc_id              int                  null,
   proc_name            varchar(64)          null,
   purtd_num            int                  null,
   purtd_outstockOK_num int                  null,
   purtd_outstockNO_num int                  null,
   purtd_total          decimal(18,2)        null,
   remark               varchar(224)         null,
   constraint PK_ORD_PURCHASE_RETURN_D primary key nonclustered (purtd_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('ord_purchase_return_d') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ord_purchase_return_d' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '进货退货明细', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purtd_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货退货明细ID',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purt_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货退货ID',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purt_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purd_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purd_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货明细ID',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purd_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'proc_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货货品',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'proc_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purtd_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货数量',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purtd_outstockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_outstockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已出库数量',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_outstockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purtd_outstockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_outstockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未出库数量',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_outstockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purtd_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货金额',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'purtd_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ord_purchase_return_d', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on ord_purchase_return_d (
purt_id ASC
)
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on ord_purchase_return_d (
purd_id ASC
)
go

/*==============================================================*/
/* Table: ord_purchase_return_h                                 */
/*==============================================================*/
create table ord_purchase_return_h (
   purt_id              int                  not null,
   purt_code            varchar(64)          null,
   purt_date            datetime             null,
   pur_id               int                  null,
   pur_code             int                  null,
   sup_id               int                  null,
   sup_name             varchar(64)          null,
   sup_linkman          varchar(64)          null,
   sup_linkphone        varchar(11)          null,
   pur_depName          varchar(64)          null,
   pur_userName         varchar(64)          null,
   purt_reason          varchar(224)         null,
   purt_categories      int                  null,
   purt_num             int                  null,
   purt_total           decimal(18,2)        null,
   purt_outstockOK_num  int                  null,
   purt_outstockNO_num  int                  null,
   purt_status          int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   approver_name        varchar(64)          null,
   approver_time        datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_ORD_PURCHASE_RETURN_H primary key nonclustered (purt_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('ord_purchase_return_h') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ord_purchase_return_h' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '退回供应商', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货退货ID',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'pur_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货订单ID',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'pur_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货编号',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货日期',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'sup_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商ID',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'sup_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'sup_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '供应商名称',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'sup_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_linkman')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'sup_linkman'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系人',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'sup_linkman'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sup_linkphone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'sup_linkphone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系电话',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'sup_linkphone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_depName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'pur_depName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货部门',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'pur_depName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'pur_userName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'pur_userName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '进货人',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'pur_userName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_reason')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_reason'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货原因',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_reason'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_categories')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_categories'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货种类',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_categories'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货数量',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货总金额',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_outstockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_outstockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已出库数量',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_outstockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_outstockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_outstockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未出库数量',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_outstockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'purt_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'purt_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'approver_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核人',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'approver_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'approver_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核时间',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'approver_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_purchase_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ord_purchase_return_h', 'column', 'remark'
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on ord_purchase_return_h (
pur_id ASC
)
go

/*==============================================================*/
/* Table: ord_sale_d                                            */
/*==============================================================*/
create table ord_sale_d (
   saled_id             int                  not null,
   sale_id              int                  null,
   proc_id              int                  null,
   proc_name            varchar(64)          null,
   proc_saled_num       int                  null,
   proc_saled_price     decimal(18,2)        null,
   proc_saled_total     decimal(18,2)        null,
   saled_outstockOK_num int                  null,
   saled_outstockNO_num int                  null,
   saled_returned_num   int                  null,
   remark               varchar(224)         null,
   constraint PK_ORD_SALE_D primary key nonclustered (saled_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('ord_sale_d') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ord_sale_d' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '销售订单明细', 
   'user', @CurrentUser, 'table', 'ord_sale_d'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saled_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'saled_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售订单明细ID',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'saled_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'sale_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售订单ID',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'sale_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品ID',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品名称',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_saled_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_saled_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售数量',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_saled_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_saled_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_saled_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售单价',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_saled_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_saled_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_saled_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售总金额',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'proc_saled_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saled_outstockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'saled_outstockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已出库数量',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'saled_outstockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saled_outstockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'saled_outstockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未出库数量',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'saled_outstockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saled_returned_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'saled_returned_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已退货数量',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'saled_returned_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ord_sale_d', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on ord_sale_d (
sale_id ASC
)
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on ord_sale_d (

)
go

/*==============================================================*/
/* Table: "ord_sale_h (销售订单表（主表）)"                              */
/*==============================================================*/
create table ord_sale_h(
   sale_id              int                  not null,
   sale_code            varchar(64)          null,
   sale_date            datetime             null,
   cust_id              int                  null,
   cust_name            varchar(64)          null,
   cust_linkman         varchar(64)          null,
   cust_linkphone       varchar(11)          null,
   sale_depId           int                  null,
   sale_depName         varchar(64)          null,
   sale_userId          int                  null,
   sale_userName        varchar(64)          null,
   sale_categories      int                  null,
   sale_num             int                  null,
   sale_total           decimal(18,2)        null,
   sale_outstockOK_num  int                  null,
   sale_outstockNO_num  int                  null,
   sale_returned_num    int                  null,
   sale_status          int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   approver_name        varchar(64)          null,
   approver_time        datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint "PK_ORD_SALE_H" primary key nonclustered (sale_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('"ord_sale_h (销售订单表（主表）)"') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '销售订单', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售订单ID',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'cust_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户Id',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'cust_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售订单编号',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售日期',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'cust_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户名称',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'cust_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_linkman')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'cust_linkman'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系人',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'cust_linkman'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_linkphone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'cust_linkphone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系电话',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'cust_linkphone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_dep')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_dep'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售部门',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_dep'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_depName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_depName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售部门',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_depName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_user')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_user'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售人',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_user'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_userName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_userName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售人',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_userName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_categories')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_categories'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售种类',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_categories'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售数量',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售总金额',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_outstockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_outstockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已出库数量',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_outstockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_outstockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_outstockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未出库数量',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_outstockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_returned_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_returned_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已退货数量',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_returned_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'sale_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'approver_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核人',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'approver_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'approver_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核时间',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'approver_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('"ord_sale_h (销售订单表（主表）)"')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ord_sale_h (销售订单表（主表）)', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on "ord_sale_h (销售订单表（主表）)" (
cust_id ASC
)
go

/*==============================================================*/
/* Table: ord_sale_return_d                                     */
/*==============================================================*/
create table ord_sale_return_d (
   saletd_id            int                  not null,
   salet_id             int                  null,
   saled_id             int                  null,
   proc_id              int                  null,
   proc_name            varchar(64)          null,
   saletd_num           int                  null,
   saletd_price         decimal(18,2)        null,
   saletd_instockOK_num int                  null,
   saletd_instockNO_num int                  null,
   saletd_total         decimal(18,2)        null,
   remark               varchar(224)         null,
   constraint PK_ORD_SALE_RETURN_D primary key nonclustered (saletd_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('ord_sale_return_d') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ord_sale_return_d' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '销售退货明细', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saletd_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售退货明细ID',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'salet_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售退货ID',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'salet_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saled_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saled_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售订单明细ID',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saled_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'proc_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品名称',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'proc_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saletd_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货数量',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saletd_instockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_instockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已入库数量',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_instockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saletd_instockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_instockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未入库数量',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_instockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'saletd_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货金额',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'saletd_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ord_sale_return_d', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on ord_sale_return_d (
salet_id ASC
)
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on ord_sale_return_d (
saled_id ASC
)
go

/*==============================================================*/
/* Table: ord_sale_return_h                                     */
/*==============================================================*/
create table ord_sale_return_h (
   salet_id             int                  not null,
   salet_code           varchar(64)          null,
   salet_date           datetime             null,
   sale_id              int                  null,
   sale_code            varchar(64)           null,
   cust_id              int                  null,
   cust_name            varchar(64)          null,
   cust_linkman         varchar(64)          null,
   cust_linkphone       varchar(11)          null,
   sale_depId           int                  null,
   sale_depName         varchar(64)          null,
   sale_userId          int                  null,
   sale_userName        varchar(64)          null,
   salet_reason         varchar(224)         null,
   salet_categories     int                  null,
   salet_num            int                  null,
   salet_total          decimal(18,2)        null,
   salet_instockOK_num  int                  null,
   salet_instockNO_num  int                  null,
   salet_status         int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   approver_name        varchar(64)          null,
   approver_time        datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_ORD_SALE_RETURN_H primary key nonclustered (salet_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('ord_sale_return_h') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'ord_sale_return_h' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '销售退货', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售退货ID',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'sale_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售订单ID',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'sale_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售退货编号',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售退货日期',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'cust_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户Id',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'cust_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'cust_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户名称',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'cust_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_linkman')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'cust_linkman'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系人',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'cust_linkman'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_linkphone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'cust_linkphone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系电话',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'cust_linkphone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_dep')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'sale_dep'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售部门',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'sale_dep'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sale_user')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'sale_user'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '销售人',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'sale_user'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_reason')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_reason'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货原因',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_reason'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_categories')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_categories'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货种类',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_categories'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货数量',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '退货总金额',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_instockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_instockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已入库数量',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_instockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_instockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_instockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未入库数量',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_instockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'salet_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'salet_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'approver_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核人',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'approver_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'approver_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核时间',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'approver_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('ord_sale_return_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'ord_sale_return_h', 'column', 'remark'
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on ord_sale_return_h (
sale_id ASC
)
go

/*==============================================================*/
/* Table: out_outstock_d                                        */
/*==============================================================*/
create table out_outstock_d (
   outd_id              int                  not null,
   slot_id              int                  null,
   out_id               int                  null,
   proc_id              int                  null,
   proc_name            varchar(64)          null,
   slot_name            varchar(64)          null,
   outd_numtotal        int                  null,
   outd_price           decimal(18,2)        null,
   outd_num             int                  null,
   outd_outstockOK_num  int                  null,
   outd_outstockNO_num  int                  null,
   outd_total           decimal(18,2)        null,
   proc_date            datetime             null,
   remark               varchar(224)         null,
   constraint PK_OUT_OUTSTOCK_D primary key nonclustered (outd_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('out_outstock_d') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'out_outstock_d' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '出库明细', 
   'user', @CurrentUser, 'table', 'out_outstock_d'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outd_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库明细ID',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'slot_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位ID',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'slot_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'out_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库ID',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'out_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品ID',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'proc_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品名称',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'proc_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'slot_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'slot_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '库位名称',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'slot_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outd_numtotal')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_numtotal'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库数量',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_numtotal'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outd_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库单价',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outd_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '本次出库数量',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outd_outstockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_outstockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已出库数量',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_outstockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outd_outstockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_outstockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未出库数量',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_outstockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outd_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库金额',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'outd_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'proc_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '生产日期',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'proc_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'out_outstock_d', 'column', 'remark'
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on out_outstock_d (
slot_id ASC
)
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on out_outstock_d (
out_id ASC
)
go

/*==============================================================*/
/* Table: out_outstock_h                                        */
/*==============================================================*/
create table out_outstock_h (
   out_id               int                  not null,
   out_code             varchar(64)          null,
   out_type             varchar(64)          null,
   wh_id                int                  null,
   wh_name              varchar(64)          null,
   out_date             datetime             null,
   out_order            varchar(64)          null,
   sup_id               int                  null,
   sup_name             varchar(64)          null,
   cust_id              int                  null,
   cust_name            varchar(64)          null,
   linkman              varchar(64)          null,
   linkphone            varchar(11)          null,
   out_user             varchar(64)          null,
   out_categories       int                  null,
   out_num              int                  null,
   out_total            decimal(18,2)        null,
   out_outstockOK_num   int                  null,
   out_outstockNO_num   int                  null,
   out_status           int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   approver_name        varchar(64)          null,
   approver_time        datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_OUT_OUTSTOCK_H primary key nonclustered (out_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('out_outstock_h') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'out_outstock_h' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '出库', 
   'user', @CurrentUser, 'table', 'out_outstock_h'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库ID',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'wh_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库ID',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'wh_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库编号',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_type')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_type'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库类型',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'wh_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'wh_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '仓库名称',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'wh_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出入日期',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_order')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_order'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '关联订单',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_order'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'cust_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户Id',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'cust_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'cust_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '客户名称',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'cust_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_linkman')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'cust_linkman'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系人',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'cust_linkman'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'cust_linkphone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'cust_linkphone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '联系电话',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'cust_linkphone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_user')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_user'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '经办人',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_user'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_categories')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_categories'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库种类',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_categories'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库数量',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库金额',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_outstockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_outstockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已出库数量',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_outstockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_outstockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_outstockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未出库数量',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_outstockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'out_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'update_name'

end


select @CurrentUser = user_name()create table bs_product_img
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'approver_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核人',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'approver_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'approver_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核时间',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'approver_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('out_outstock_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'out_outstock_h', 'column', 'remark'
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on out_outstock_h (
wh_id ASC
)
go

/*==============================================================*/
/* Table: public_file                                           */
/*==============================================================*/
create table public_file (
   file_id              int                  not null,
   business_type        varchar(64)          null,
   business_code        varchar(64)          null,
   file_name            varchar(64)          null,
   constraint PK_PUBLIC_FILE primary key nonclustered (file_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('public_file') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'public_file' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '附件信息', 
   'user', @CurrentUser, 'table', 'public_file'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('public_file')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'file_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'public_file', 'column', 'file_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '附件ID',
   'user', @CurrentUser, 'table', 'public_file', 'column', 'file_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('public_file')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'business_type')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'public_file', 'column', 'business_type'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '附件业务类型',
   'user', @CurrentUser, 'table', 'public_file', 'column', 'business_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('public_file')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'business_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'public_file', 'column', 'business_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '对应业务编号',
   'user', @CurrentUser, 'table', 'public_file', 'column', 'business_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('public_file')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'file_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'public_file', 'column', 'file_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '附件路径',
   'user', @CurrentUser, 'table', 'public_file', 'column', 'file_name'
go

/*==============================================================*/
/* Table: sys_business_type                                     */
/*==============================================================*/
create table sys_business_type (
   bus_id               int                  not null,
   bus_name             varchar(64)          null,
   bus_sort             int                  null,
   bus_field            varchar(64)          null,
   bus_status           int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_SYS_BUSINESS_TYPE primary key nonclustered (bus_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('sys_business_type') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'sys_business_type' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '出入库，盘掉调拨类型信息', 
   'user', @CurrentUser, 'table', 'sys_business_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'bus_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '业务类型ID',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'bus_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '业务类型名称',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'bus_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'bus_field')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_field'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '方向',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_field'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'bus_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'bus_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_business_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'sys_business_type', 'column', 'remark'
go

/*==============================================================*/
/* Table: sys_code_rule                                         */
/*==============================================================*/
create table sys_code_rule (
   code_id              int                  not null,
   code_name            varchar(64)          null,
   code_prefix          varchar(64)          null,
   timerule             varchar(64)          null,
   code_num             int                  null,
   code_step            int                  null,
   numberrule           varchar(64)          null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   constraint PK_SYS_CODE_RULE primary key nonclustered (code_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('sys_code_rule') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'sys_code_rule' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '单据编号规则表', 
   'user', @CurrentUser, 'table', 'sys_code_rule'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'code_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '编号规则ID',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'code_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '目标表单',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'code_prefix')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_prefix'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '前缀',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_prefix'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'timerule')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'timerule'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '时间规则',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'timerule'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'code_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '流水号/位',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'code_step')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_step'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '步长',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'code_step'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'numberrule')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'numberrule'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '编号生成规则',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'numberrule'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_code_rule')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'sys_code_rule', 'column', 'is_delete'
go

/*==============================================================*/
/* Table: sys_dict_data                                         */
/*==============================================================*/
create table sys_dict_data (
   dict_code            int                  not null,
   dict_id              int                  null,
   dict_sort            int                  null,
   dict_label           varchar(64)          null,
   dict_value           int                  null,
   is_default           int                  null,
   status               int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_SYS_DICT_DATA primary key nonclustered (dict_code)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('sys_dict_data') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'sys_dict_data' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '字典类型数据详细信息', 
   'user', @CurrentUser, 'table', 'sys_dict_data'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dict_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '字典数据主键',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dict_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '字典类型ID',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dict_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dict_label')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_label'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '标签',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_label'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dict_value')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_value'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '键值',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'dict_value'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_default')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'is_default'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '是否默认值',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'is_default'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_data')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'sys_dict_data', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on sys_dict_data (
dict_id ASC
)
go

/*==============================================================*/
/* Table: sys_dict_type                                         */
/*==============================================================*/
create table sys_dict_type (
   dict_id              int                  not null,
   dict_typename        varchar(64)          null,
   dict_status          int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_SYS_DICT_TYPE primary key nonclustered (dict_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('sys_dict_type') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'sys_dict_type' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '单据状态等信息', 
   'user', @CurrentUser, 'table', 'sys_dict_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dict_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'dict_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '字典类型ID',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'dict_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dict_typename')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'dict_typename'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '字典类型名称',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'dict_typename'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dict_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'dict_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'dict_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_dict_type')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'sys_dict_type', 'column', 'remark'
go

/*==============================================================*/
/* Table: sys_info                                              */
/*==============================================================*/
create table sys_info (
   info_id              int                  not null,
   info_text            varchar(224)         null,
   info_type            varchar(64)          null,
   info_status          int                  null,
   info_time            datetime             null,
   constraint PK_SYS_INFO primary key nonclustered (info_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('sys_info') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'sys_info' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '提示信息内容', 
   'user', @CurrentUser, 'table', 'sys_info'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_info')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'info_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '信息ID',
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_info')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'info_text')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_text'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '信息内容',
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_text'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_info')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'info_type')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_type'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '信息类型',
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_info')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'info_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '信息状态',
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('sys_info')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'info_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '接收时间',
   'user', @CurrentUser, 'table', 'sys_info', 'column', 'info_time'
go

/*==============================================================*/
/* Table: tr_allot_d                                            */
/*==============================================================*/
create table tr_allot_d (
   ald_id               int                  not null,
   al_id                int                  null,
   proc_id              int                  null,
   proc_name            varchar(64)          null,
   ald_num              int                  null,
   ald_price            decimal(18,2)        null,
   ald_total            decimal(18,2)        null,
   instock_status       int                  null,
   outstock_status      int                  null,
   ald_outstockOK_num   int                  null,
   ald_outstockNO_num   int                  null,
   ald_instockOK_num    int                  null,
   ald_instockNO_num    int                  null,
   remark               varchar(224)         null,
   constraint PK_TR_ALLOT_D primary key nonclustered (ald_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('tr_allot_d') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'tr_allot_d' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '调拨明细', 
   'user', @CurrentUser, 'table', 'tr_allot_d'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ald_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨明细ID',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'al_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨ID',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'al_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'proc_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品ID',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'proc_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'proc_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'proc_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '货品名称',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'proc_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ald_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨数量',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ald_price')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_price'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨单价',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_price'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ald_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨总金额',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'instock_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'instock_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库状态',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'instock_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outstock_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'outstock_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库状态',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'outstock_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ald_outstockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_outstockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已出库数量',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_outstockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ald_outstockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_outstockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未出库数量',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_outstockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ald_instockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_instockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已入库数量',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_instockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'ald_instockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_instockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未入库数量',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'ald_instockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_d')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'tr_allot_d', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on tr_allot_d (
al_id ASC
)
go

/*==============================================================*/
/* Table: tr_allot_h                                            */
/*==============================================================*/
create table tr_allot_h (
   al_id                int                  not null,
   al_code              varchar(64)          null,
   al_type              varchar(64)          null,
   al_date              datetime             null,
   out_wh_id            int                  null,
   out_wh_name          varchar(64)          null,
   in_wh_id             int                  null,
   in_wh_name           varchar(64)          null,
   al_user              varchar(64)          null,
   al_categories        int                  null,
   al_num               int                  null,
   al_total             decimal(18,2)        null,
   al_outstockOK_num    int                  null,
   al_outstockNO_num    int                  null,
   al_instockOK_num     int                  null,
   al_instockNO_num     int                  null,
   instock_status       int                  null,
   outstock_status      int                  null,
   al_status            int                  null,
   create_name          varchar(64)          null,
   create_time          datetime             null,
   update_name          varchar(64)          null,
   update_time          datetime             null,
   approver_name        varchar(64)          null,
   approver_time        datetime             null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_TR_ALLOT_H primary key nonclustered (al_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('tr_allot_h') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'tr_allot_h' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '调拨', 
   'user', @CurrentUser, 'table', 'tr_allot_h'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨ID',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨编号',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_type')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_type'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨类型',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_type'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_date')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_date'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨日期',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_date'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_wh_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'out_wh_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调出仓库ID',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'out_wh_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'out_wh_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'out_wh_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调出仓库名称',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'out_wh_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_wh_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'in_wh_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调入仓库ID',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'in_wh_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'in_wh_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'in_wh_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调入仓库名称',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'in_wh_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_user')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_user'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '经办人',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_user'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_categories')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_categories'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨种类',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_categories'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨数量',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_total')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_total'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '调拨数量',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_total'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_outstockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_outstockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已出库数量',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_outstockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_outstockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_outstockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未出库数量',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_outstockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_instockOK_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_instockOK_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '已入库数量',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_instockOK_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_instockNO_num')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_instockNO_num'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '未入库数量',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_instockNO_num'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'instock_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'instock_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '入库状态',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'instock_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'outstock_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'outstock_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '出库状态',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'outstock_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'al_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'al_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'create_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建人',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'create_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'create_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'create_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '创建时间',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'create_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'update_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新人',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'update_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'update_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'update_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '更新时间',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'update_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'approver_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核人',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'approver_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'approver_time')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'approver_time'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '审核时间',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'approver_time'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('tr_allot_h')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'tr_allot_h', 'column', 'remark'
go

/*==============================================================*/
/* Table: zct_department                                        */
/*==============================================================*/
create table zct_department (
   department_id        int                  not null,
   department_code      varchar(64)          null,
   department_name      varchar(64)          null,
   department_status    int                  null,
   department_sort      int                  null,
   department_parentid  int                  null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_ZCT_DEPARTMENT primary key nonclustered (department_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('zct_department') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'zct_department' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '部门信息', 
   'user', @CurrentUser, 'table', 'zct_department'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_department')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'department_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '部门ID',
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_department')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'department_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '部门编号',
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_department')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'department_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '部门名称',
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_department')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'department_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '部门状态',
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_department')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'department_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_department')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'department_parentid')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_parentid'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '父级ID',
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'department_parentid'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_department')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_department')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'zct_department', 'column', 'remark'
go

/*==============================================================*/
/* Table: zct_permission                                        */
/*==============================================================*/
create table zct_permission (
   permission_id        int                  not null,
   permission_code      varchar(64)          null,
   permission_name      varchar(64)          null,
   permission_address   varchar(64)          null,
   permission_status    int                  null,
   permission_parentid  int                  null,
   permission_sort      int                  null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_ZCT_PERMISSION primary key nonclustered (permission_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('zct_permission') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'zct_permission' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '菜单信息（一个角色可有多个菜单权限，一个菜单权限多个角色可以用）', 
   'user', @CurrentUser, 'table', 'zct_permission'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'permission_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '权限ID',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'permission_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '权限编号',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'permission_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '权限名称',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'permission_address')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_address'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '权限地址',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_address'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'permission_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '权限状态',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'permission_parentid')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_parentid'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '父级ID',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_parentid'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'permission_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'permission_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_permission')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'zct_permission', 'column', 'remark'
go

/*==============================================================*/
/* Table: zct_position                                          */
/*==============================================================*/
create table zct_position (
   position_id          int                  not null,
   position_code        varchar(64)          null,
   position_name        varchar(64)          null,
   position_status      int                  null,
   position_sort        int                  null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_ZCT_POSITION primary key nonclustered (position_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('zct_position') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'zct_position' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '岗位信息', 
   'user', @CurrentUser, 'table', 'zct_position'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_position')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'position_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '岗位ID',
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_position')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'position_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '岗位编号',
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_position')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'position_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '岗位名称',
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_position')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'position_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '岗位状态',
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_position')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'position_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'position_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_position')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_position')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'zct_position', 'column', 'remark'
go

/*==============================================================*/
/* Table: zct_role                                              */
/*==============================================================*/
create table zct_role (
   role_id              int                  not null,
   role_code            varchar(64)          null,
   role_name            varchar(64)          null,
   role_status          int                  null,
   role_sort            int                  null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_ZCT_ROLE primary key nonclustered (role_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('zct_role') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'zct_role' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '角色信息（用户可有多个角色身份）', 
   'user', @CurrentUser, 'table', 'zct_role'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'role_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色ID',
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'role_code')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_code'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色编号',
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_code'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'role_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色名称',
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'role_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色状态',
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'role_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'role_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_role')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'zct_role', 'column', 'remark'
go

/*==============================================================*/
/* Table: zct_user                                              */
/*==============================================================*/
create table zct_user (
   user_id              int                  not null,
   department_id        int                  null,
   position_id          int                  null,
   user_account         varchar(64)          null,
   user_password        varchar(64)          null,
   user_name            varchar(64)          null,
   user_sex             int                  null,
   user_phone           varchar(11)          null,
   user_avatar          varchar(64)          null,
   user_status          int                  null,
   user_sort            int                  null,
   is_delete            int                  null,
   remark               varchar(224)         null,
   constraint PK_ZCT_USER primary key nonclustered (user_id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('zct_user') and minor_id = 0)
begin 
   declare @CurrentUser sysname 
select @CurrentUser = user_name() 
execute sp_dropextendedproperty 'MS_Description',  
   'user', @CurrentUser, 'table', 'zct_user' 
 
end 


select @CurrentUser = user_name() 
execute sp_addextendedproperty 'MS_Description',  
   '用户信息', 
   'user', @CurrentUser, 'table', 'zct_user'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '用户ID',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'department_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'department_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '部门ID',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'department_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'position_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'position_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '岗位ID',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'position_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_account')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_account'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '用户账号',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_account'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_password')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_password'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '用户密码',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_password'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '姓名',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_sex')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_sex'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '性别',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_sex'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_phone')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_phone'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '手机号',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_phone'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_avatar')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_avatar'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '头像',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_avatar'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_status')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_status'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '状态',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_status'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_sort')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_sort'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '排序',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'user_sort'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_delete')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'is_delete'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '删除标识',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'is_delete'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('zct_user')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '备注',
   'user', @CurrentUser, 'table', 'zct_user', 'column', 'remark'
go

/*==============================================================*/
/* Index: 拥有_FK                                                 */
/*==============================================================*/
create index 拥有_FK on zct_user (
department_id ASC
)
go

/*==============================================================*/
/* Index: 拥有_FK2                                                */
/*==============================================================*/
create index 拥有_FK2 on zct_user (
position_id ASC
)
go

/*==============================================================*/
/* Table: 对应                                                    */
/*==============================================================*/
create table 对应 (
   role_id              int                  not null,
   user_id              int                  not null,
   constraint PK_对应 primary key nonclustered (role_id, user_id)
)
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('对应')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'role_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', '对应', 'column', 'role_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色ID',
   'user', @CurrentUser, 'table', '对应', 'column', 'role_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('对应')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'user_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', '对应', 'column', 'user_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '用户ID',
   'user', @CurrentUser, 'table', '对应', 'column', 'user_id'
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on 对应 (
user_id ASC
)
go

/*==============================================================*/
/* Index: 对应_FK2                                                */
/*==============================================================*/
create index 对应_FK2 on 对应 (
role_id ASC
)
go

/*==============================================================*/
/* Table: 对应2                                                   */
/*==============================================================*/
create table 对应2 (
   role_id              int                  not null,
   permission_id        int                  not null,
   constraint PK_对应2 primary key nonclustered (role_id, permission_id)
)
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('对应2')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'role_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', '对应2', 'column', 'role_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '角色ID',
   'user', @CurrentUser, 'table', '对应2', 'column', 'role_id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('对应2')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'permission_id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description', 
   'user', @CurrentUser, 'table', '对应2', 'column', 'permission_id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description', 
   '权限ID',
   'user', @CurrentUser, 'table', '对应2', 'column', 'permission_id'
go

/*==============================================================*/
/* Index: 对应_FK                                                 */
/*==============================================================*/
create index 对应_FK on 对应2 (
permission_id ASC
)
go

/*==============================================================*/
/* Index: 对应_FK2                                                */
/*==============================================================*/
create index 对应_FK2 on 对应2 (
role_id ASC
)
go

alter table bs_product
   add constraint FK_BS_PRODU_拥有_BS_PRODU foreign key (type_id)
      references bs_product_type (type_id)
go

alter table "bs_product_img (货品信息图片表)"
   add constraint FK_BS_PRODU_拥有_BS_PRODU foreign key (proc_id)
      references bs_product (proc_id)
go

alter table bs_product_unit
   add constraint FK_BS_PRODU_拥有_BS_PRODU foreign key (proc_id)
      references bs_product (proc_id)
go

alter table bs_slot
   add constraint FK_BS_SLOT_拥有_BS_WAREH foreign key (wh_id)
      references bs_warehouse (wh_id)
go

alter table bs_stock
   add constraint FK_BS_STOCK_拥有_BS_PRODU foreign key (proc_id)
      references bs_product (proc_id)
go

alter table bs_stock
   add constraint FK_BS_STOCK_拥有_BS_SLOT foreign key (slot_id)
      references bs_slot (slot_id)
go

alter table bs_stock
   add constraint FK_BS_STOCK_拥有_BS_WAREH foreign key (wh_id)
      references bs_warehouse (wh_id)
go

alter table ic_check_d
   add constraint FK_IC_CHECK_对应_BS_SLOT foreign key (slot_id)
      references bs_slot (slot_id)
go

alter table ic_check_d
   add constraint FK_IC_CHECK_拥有_IC_CHECK foreign key (ic_id)
      references "ic_check_h （盘点表（主表））" (ic_id)
go

alter table "ic_check_h （盘点表（主表））"
   add constraint FK_IC_CHECK_对应_BS_WAREH foreign key (wh_id)
      references bs_warehouse (wh_id)
go

alter table in_instock_d
   add constraint FK_IN_INSTO_对应_BS_SLOT foreign key (slot_id)
      references bs_slot (slot_id)
go

alter table in_instock_d
   add constraint FK_IN_INSTO_拥有_IN_INSTO foreign key (in_id)
      references in_instock_h (in_id)
go

alter table in_instock_h
   add constraint FK_IN_INSTO_对应_BS_WAREH foreign key (wh_id)
      references bs_warehouse (wh_id)
go

alter table ord_purchase_d
   add constraint FK_ORD_PURC_对应_BS_PRODU foreign key (proc_id)
      references bs_product (proc_id)
go

alter table ord_purchase_d
   add constraint FK_ORD_PURC_拥有_ORD_PURC foreign key (pur_id)
      references ord_purchase_h (pur_id)
go

alter table ord_purchase_h
   add constraint FK_ORD_PURC_拥有_BS_SUPPL foreign key (sup_id)
      references bs_supplier (sup_id)
go

alter table ord_purchase_return_d
   add constraint FK_ORD_PURC_对应_ORD_PURC foreign key (purd_id)
      references ord_purchase_d (purd_id)
go

alter table ord_purchase_return_d
   add constraint FK_ORD_PURC_拥有_ORD_PURC foreign key (purt_id)
      references ord_purchase_return_h (purt_id)
go

alter table ord_purchase_return_h
   add constraint FK_ORD_PURC_对应_ORD_PURC foreign key (pur_id)
      references ord_purchase_h (pur_id)
go

alter table ord_sale_d
   add constraint FK_ORD_SALE_对应_BS_STOCK foreign key ()
      references bs_stock
go

alter table ord_sale_d
   add constraint FK_ORD_SALE_拥有_ORD_SALE foreign key (sale_id)
      references "ord_sale_h (销售订单表（主表）)" (sale_id)
go

alter table "ord_sale_h (销售订单表（主表）)"
   add constraint FK_ORD_SALE_拥有_BS_CUSTO foreign key (cust_id)
      references bs_customer (cust_id)
go

alter table ord_sale_return_d
   add constraint FK_ORD_SALE_对应_ORD_SALE foreign key (saled_id)
      references ord_sale_d (saled_id)
go

alter table ord_sale_return_d
   add constraint FK_ORD_SALE_拥有_ORD_SALE foreign key (salet_id)
      references ord_sale_return_h (salet_id)
go

alter table ord_sale_return_h
   add constraint FK_ORD_SALE_对应_ORD_SALE foreign key (sale_id)
      references "ord_sale_h (销售订单表（主表）)" (sale_id)
go

alter table out_outstock_d
   add constraint FK_OUT_OUTS_对应_BS_SLOT foreign key (slot_id)
      references bs_slot (slot_id)
go

alter table out_outstock_d
   add constraint FK_OUT_OUTS_拥有_OUT_OUTS foreign key (out_id)
      references out_outstock_h (out_id)
go

alter table out_outstock_h
   add constraint FK_OUT_OUTS_对应_BS_WAREH foreign key (wh_id)
      references bs_warehouse (wh_id)
go

alter table sys_dict_data
   add constraint FK_SYS_DICT_拥有_SYS_DICT foreign key (dict_id)
      references sys_dict_type (dict_id)
go

alter table tr_allot_d
   add constraint FK_TR_ALLOT_拥有_TR_ALLOT foreign key (al_id)
      references tr_allot_h (al_id)
go

alter table zct_user
   add constraint FK_ZCT_USER_拥有_ZCT_DEPA foreign key (department_id)
      references zct_department (department_id)
go

alter table zct_user
   add constraint FK_ZCT_USER_拥有_ZCT_POSI foreign key (position_id)
      references zct_position (position_id)
go

alter table 对应
   add constraint FK_对应_对应_ZCT_ROLE foreign key (role_id)
      references zct_role (role_id)
go

alter table 对应
   add constraint FK_对应_对应_ZCT_USER foreign key (user_id)
      references zct_user (user_id)
go

alter table 对应2
   add constraint FK_对应2_对应_ZCT_PERM foreign key (permission_id)
      references zct_permission (permission_id)
go

alter table 对应2
   add constraint FK_对应2_对应_ZCT_ROLE foreign key (role_id)
      references zct_role (role_id)
go

